<!--
本页面authStatus != 2
-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司名称" prop="companyname">
        <el-input
          v-model="queryParams.companyname"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <!-- <el-form-item label="会员类型" prop="memberPriceTemplateId">
         <el-select v-model="queryParams.memberPriceTemplateId" placeholder="请选择会员类型">
            <el-option
              v-for="dict in dict.type.sys_vip_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
      </el-form-item> -->
      
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:investor:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="investorList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="公司名称" align="center" prop="companyname" />
      
     
      
      <el-table-column label="认证状态" align="center" prop="authStatus" >  
        <template slot-scope="scope">
          <dict-tag :options="dict.type.member_auth_status" :value="scope.row.authStatusAll.authStatus"/>
        </template>
      </el-table-column>/>
      <el-table-column label="用户头像" align="center" prop="picsId" >
        <template slot-scope="scope">
               <img :src="scope.row.picsId" min-width="50" height="50"/>
       </template>
      </el-table-column>
      <el-table-column label="案例列表 " align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleViewCase(scope.row.id)"
            v-hasPermi="['system:investor:edit']"
          >查看案例 </el-button>
          
        </template>
      </el-table-column>
     
      
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="联系方式" align="center" prop="tel" />
      <el-table-column label="上传资料" align="center" prop="upinfo" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:investor:edit']"
          >认证操作</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:investor:remove']"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改投资人对话框，开启此对话框才进行对应用户user内容的查询 -->
    <el-dialog title="投资人认证" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司名称" prop="companyname">
          <el-input v-model="form.companyname" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="公司任职" prop="position">
          <el-input v-model="form.position" placeholder="请输入公司任职" />
        </el-form-item>
        <el-form-item label="vip缴费时间" prop="chargeTime">
          <el-date-picker clearable disabled
            v-model="form.chargeTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择vip缴费时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会员类型" prop="memberPriceTemplateId">
           <el-select v-model="form.memberPriceTemplateId" placeholder="请选择会员类型" disabled>
            <el-option
              v-for="dict in dict.type.sys_vip_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
       
        <el-form-item label="用户账号" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户登录账号" :disabled="username_disable_flag" />
        </el-form-item>
        <el-form-item label="上传照片" prop="picsId">
            <el-popover placement="top-start" trigger="click">
              <a :href="form.picsId" target="_blank" title="查看图片">
                <img :src="form.picsId" style="width: 500px;height: 400px">
              </a>
            <img slot="reference" :src="form.picsId" style="width: 50px;height: 50px; cursor:pointer">
        </el-popover>
       
        </el-form-item>
        <el-form-item label="案例列表" prop="casesId">
         <template v-for="i in caseObjList">
          <el-tag>{{i.caseName}}</el-tag>
         </template>
        </el-form-item>
        
        <el-form-item label="vip到期时间" prop="vipendTime">
          <el-date-picker clearable disabled
            v-model="form.vipendTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择vip到期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="真实姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入真实姓名" />
        </el-form-item>
        <el-form-item label="联系方式" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入联系方式" />
        </el-form-item>
        <el-form-item label="审核资料" prop="upinfo">
          <a :href="form.upinfo" target="_blank" title="查看">
            查看
          </a>
        </el-form-item>
       
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm(0)">通过</el-button>
        <el-button type="danger" @click="submitForm(1)">拒绝</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog title="用户案例查看" :visible.sync="open2" width="800px" append-to-body>
      <el-table v-loading="loading" :data="caseList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <!-- <el-table-column label="会员id" align="center" prop="memberInvestorId" /> -->
      <el-table-column label="案例名称" align="center" prop="caseName" />
      <!-- <el-table-column label="用户主id" align="center" prop="userId" /> -->
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="昵称" align="center" prop="nickName" />
    </el-table>
      
      <div slot="footer" class="dialog-footer">       
        <el-button @click="open2 = false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCase } from "@/api/member/case";
import { listInvestorForAuth, getInvestor, delInvestor, auditInvestor } from "@/api/system/investor";
import { listUser, getUser, delUser, addUser, updateUser, resetUserPwd, changeUserStatus } from "@/api/system/user";

export default {
  name: "Investor",
  dicts: ['sys_yes_no', 'sys_vip_type', 'member_auth_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedSysUser: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 投资人表格数据
      investorList: [],
      // 用户信息表格数据
      sysUserList: [],
      // 会员案例表格数据
      caseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      caseObjList: [],
      // 查询参数
      username_disable_flag: false,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 查询案例参数
      queryParams2: {
        pageNum: 1,
        pageSize: 1000,
        name: null,
        addrProvince: null,
        addrCity: null,
        ifAvailable: null,
        ifPaid: null,
        sortId: null,
        memberInvestorId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        isSupplier: [
          { required: true, message: "是否供应商不能为空", trigger: "change" }
        ],
        isScenespot: [
          { required: true, message: "是否景区不能为空", trigger: "change" }
        ],
        isVip: [
          { required: true, message: "是否vip会员不能为空", trigger: "change" }
        ],
        userName: [
          { required: true, message: "用户账号不能为空", trigger: "blur" }
        ],
        authStatus: [
          { required: true, message: "认证状态不能为空", trigger: "blur" }
        ],
        realName: [
          { required: true, message: "真实姓名不能为空", trigger: "blur" }
        ],
        upinfo: [
          { required: true, message: "上传资料不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询投资人列表 */
    getList() {
      this.loading = true;
      listInvestorForAuth(this.queryParams).then(response => {
        this.investorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyname: null,
        position: null,
        chargeTime: null,
        memberPriceTemplateId: null,
        isSupplier: null,
        isScenespot: null,
        isVip: null,
        sceneId: null,
        supplierId: null,
        userName: null,
        authStatus: "0",
        picsId: null,
        casesId: null,
        chargeHisId: null,
        vipendTime: null,
        realName: null,
        tel: null,
        upinfo: null,
        caseObjList: []
      };
      this.sysUserList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查询景区基础数据列表 */
    getCaseList() {
      this.loading = true;
      listCase(this.queryParams2).then(response => {
        this.caseList = response.rows;
       // this.total = response.total;
        this.loading = false;
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.username_disable_flag = false;
      this.open = true;
      this.title = "添加投资人";
    },
    /**查看案例弹出窗*/
    handleViewCase(id) {
      this.open2 = true
      this.queryParams2.memberInvestorId = id
      this.getCaseList()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.caseObjList = JSON.parse(JSON.stringify(row.casesObj));
      this.username_disable_flag = true;
      const id = row.id || this.ids
      getInvestor(id).then(response => {
        this.form = response.data;
        this.open = true;
      });
    },
    
    /** 投资人认证用*/

    submitForm(flag) {
      let retval = null;
      if(flag == 0) this.form.isAuth = "Y"
      else if(flag == 1) this.form.isAuth = "N"

      auditInvestor(this.form).then(response => {
      this.$modal.msgSuccess("修改成功");
      this.open = false;
      this.getList();
    });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除投资人编号为"' + ids + '"的数据项？').then(function() {
        return delInvestor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 用户信息序号 */
    rowSysUserIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 用户信息添加按钮操作 
    handleAddSysUser() {
      let obj = {};
      obj.deptId = "";
      obj.userName = "";
      obj.nickName = "";
      obj.userType = "";
      obj.email = "";
      obj.phonenumber = "";
      obj.sex = "";
      obj.avatar = "";
      obj.password = "";
      obj.status = "";
      obj.loginIp = "";
      obj.loginDate = "";
      obj.remark = "";
      this.sysUserList.push(obj);
    },*/
    /** 用户信息删除按钮操作 */
    handleDeleteSysUser() {
      if (this.checkedSysUser.length == 0) {
        this.$modal.msgError("请先选择要删除的用户信息数据");
      } else {
        const sysUserList = this.sysUserList;
        const checkedSysUser = this.checkedSysUser;
        this.sysUserList = sysUserList.filter(function(item) {
          return checkedSysUser.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleSysUserSelectionChange(selection) {
      this.checkedSysUser = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/investor/export', {
        ...this.queryParams
      }, `investor_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
